//
//  FooterMenuView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/25.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "FooterMenuView.h"
#import "config.h"
#import "Tools.h"

@implementation FooterMenuView
@synthesize selectAllBtn,moveBtn,beUnAbleBtn,beAbleBtn;

+(instancetype)creatView{

    return [[self alloc]initWithFrame:CGRectMake(0,UIScreenHeight - 64 - 40, UIScreenWidth, 40)];
}
#pragma mark 全选
- (void)selectAllBtnOnClick:(UIButton *)btn {
    
    NSInteger tag = btn.tag;
    if (self.delegate && [self.delegate respondsToSelector:@selector(footerMenuViewSelectAllBtnOnClicked)]){
        
        [self.delegate footerMenuViewSelectAllBtnOnClicked];
        
    
    if (tag == 0) {
         [selectAllBtn setImage:[UIImage imageNamed:@"fuxuan_birder_si"] forState:UIControlStateNormal];
    }else
    {
         [selectAllBtn setImage:[UIImage imageNamed:@"fuxuan_birder"] forState:UIControlStateNormal];
    }
     btn.tag = tag == 0?1:0;
    }
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        CGFloat btnHeigth = 25;
        CGFloat btnWidth = 50;
        CGFloat btnWidth2 = 68;
        CGFloat margin = 10;
        CGFloat btnY = (self.frame.size.height - btnHeigth)/2;
        
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, 1)];
        [line1 setBackgroundColor:UIColorFromRGB(0xe3e3e3)];
        [self addSubview:line1];
        
        
        
        //全选
        selectAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        selectAllBtn.frame = CGRectMake(0, (self.frame.size.height - 32)/2, btnWidth2, 32);
        [selectAllBtn setImage:[UIImage imageNamed:@"fuxuan_birder"] forState:UIControlStateNormal];
        [selectAllBtn setTitle:@"全选" forState:UIControlStateNormal];
        [selectAllBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        [selectAllBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [selectAllBtn setImage:[UIImage imageNamed:@"fuxuan_birder_si"] forState:UIControlStateHighlighted];
        [selectAllBtn addTarget:self action:@selector(selectAllBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
//        [selectAllBtn setBackgroundImage:[UIImage imageNamed:@"btn_pressed"] forState:UIControlStateHighlighted];
         selectAllBtn.imageEdgeInsets = UIEdgeInsetsMake(8, 18, 8, 35);
        selectAllBtn.tag = 0;
        [self addSubview:selectAllBtn];
        
        
        //启用
        beAbleBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        beAbleBtn.frame = CGRectMake(btnWidth2 + margin,btnY, btnWidth, btnHeigth);
        [beAbleBtn setTitle:@"启用" forState:UIControlStateNormal];
        [beAbleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [beAbleBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [beAbleBtn addTarget:self action:@selector(beAbleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        beAbleBtn.tag = 1;
        [beAbleBtn setBackgroundImage:[UIImage imageNamed:@"btn_pressed"] forState:UIControlStateHighlighted];
        [beAbleBtn setBackgroundImage:[Tools getImgByColor:UIColorFromRGB(0x58bf66)] forState:UIControlStateNormal];
        [self addSubview:beAbleBtn];
        
        //禁用
        beUnAbleBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        beUnAbleBtn.frame = CGRectMake(btnWidth + btnWidth2+ margin*2,btnY, btnWidth, btnHeigth);
        [beUnAbleBtn setTitle:@"禁用" forState:UIControlStateNormal];
        [beUnAbleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [beUnAbleBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        
        [beUnAbleBtn addTarget:self action:@selector(beUnAbleBtn:) forControlEvents:UIControlEventTouchUpInside];
        beUnAbleBtn.tag = 1;
        [beUnAbleBtn setBackgroundImage:[Tools getImgByColor:UIColorFromRGB(0xdb2a2b)] forState:UIControlStateNormal];
        [beUnAbleBtn setBackgroundImage:[UIImage imageNamed:@"btn_pressed"] forState:UIControlStateHighlighted];
        [self addSubview:beUnAbleBtn];
        
        //移动
        
        moveBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        moveBtn.frame = CGRectMake(2*btnWidth +btnWidth2+ margin*3,btnY, btnWidth, btnHeigth);
        [moveBtn setTitle:@"移动" forState:UIControlStateNormal];
        [moveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [moveBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [moveBtn addTarget:self action:@selector(moveBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        moveBtn.tag = 2;
        [moveBtn setBackgroundImage:[Tools getImgByColor:UIColorFromRGB(0xeca909 )] forState:UIControlStateNormal];
        [moveBtn setBackgroundImage:[UIImage imageNamed:@"btn_pressed"] forState:UIControlStateHighlighted];
        [self addSubview:moveBtn];
        
        [self setBackgroundColor:[UIColor whiteColor]];
        
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 39, UIScreenWidth, 1)];
        [line2 setBackgroundColor:UIColorFromRGB(0xe3e3e3)];
        [self addSubview:line2];
        
    }
    return self;
}

#pragma mark 启用
- (void)beAbleBtnClick:(id)sender {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(footerMenuViewBeAbleBtnOnClicked)]) {
        [self.delegate footerMenuViewBeAbleBtnOnClicked];
    }
}

#pragma mark 禁用
- (void)beUnAbleBtn:(id)sender {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(footerMenuViewbeUnAbleBtnOnClicked)]) {
        [self.delegate footerMenuViewbeUnAbleBtnOnClicked];
    }
}
#pragma mark 移动
- (void)moveBtnClick:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(footerMenuViewbeMoveBtnOnClicked)]) {
        [self.delegate footerMenuViewbeMoveBtnOnClicked];
    }
}

@end
